This is a refactored version of a previous patch that destroys external
authorEwan Mellor <ewan@xensource.com>
Tue, 21 Nov 2006 10:22:19 +0000 (10:22 +0000)
committerEwan Mellor <ewan@xensource.com>
Tue, 21 Nov 2006 10:22:19 +0000 (10:22 +0000)
devices' state when a VM configuration file is destroyed. Currently only
the vTPM device's state needs to be explicitly destroyed.
I am also surrounding the saving of the managed domain's configuration
with a try-catch.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
tools/python/xen/xend/XendAPI.py
tools/python/xen/xend/XendConstants.py
tools/python/xen/xend/XendDevices.py
tools/python/xen/xend/XendDomain.py
tools/python/xen/xend/server/tpmif.py

index fba16a812fdfe8c45bd41c24584a7ad4451ca7d7..9ac9996d796d307d70e16b93a33be7aa77e46370 100644 (file)
@@ -1391,9 +1391,12 @@ class XendAPI:
         xendom = XendDomain.instance()
         if xendom.is_valid_vm(vtpm_struct['VM']):
             dom = xendom.get_vm_by_uuid(vtpm_struct['VM'])
-            vtpm_ref = dom.create_vtpm(vtpm_struct)
-            xendom.managed_config_save(dom)
-            return xen_api_success(vtpm_ref)
+            try:
+                vtpm_ref = dom.create_vtpm(vtpm_struct)
+                xendom.managed_config_save(dom)
+                return xen_api_success(vtpm_ref)
+            except XendError:
+                return xen_api_error(XEND_ERROR_TODO)
         else:
             return xen_api_error(XEND_ERROR_DOMAIN_INVALID)
 
index d956c2fe4a5b3763892acf10e4b408bb7cbda08b..96f7a22d7ebdaa3de805469b413ce82aa86a98d5 100644 (file)
@@ -88,6 +88,12 @@ DEV_MIGRATE_STEP1 = 1
 DEV_MIGRATE_STEP2 = 2
 DEV_MIGRATE_STEP3 = 3
 
+#
+# VTPM-related constants
+#
+
+VTPM_DELETE_SCRIPT = '/etc/xen/scripts/vtpm-delete'
+
 #
 # Xenstore Constants
 #
index 2286824087c83d3d14b107731707b23d7f784320..ce91e2827136ecdb3e289b84cd0dab8defc299ee 100644 (file)
@@ -71,3 +71,13 @@ class XendDevices:
 
     make_controller = classmethod(make_controller)
 
+    def destroy_device_state(cls, domain):
+        """Destroy the state of (external) devices. This is necessary
+           to do when a VM's configuration is destroyed.
+        
+        @param domain: domain this controller is handling devices for.
+        @type domain: XendDomainInfo
+        """
+        tpmif.destroy_vtpmstate(domain.getName())
+
+    destroy_device_state = classmethod(destroy_device_state)
index 0bf1b63a37e09473370d0434786def987012ad49..c32ec29390835d02d3cc86ea18ad90cb94279d57 100644 (file)
@@ -37,6 +37,7 @@ from xen.xend.XendError import XendError, XendInvalidDomain, VmError
 from xen.xend.XendLogging import log
 from xen.xend.XendConstants import XS_VMROOT
 from xen.xend.XendConstants import DOM_STATE_HALTED, DOM_STATE_RUNNING
+from xen.xend.XendDevices import XendDevices
 
 from xen.xend.xenstore.xstransact import xstransact
 from xen.xend.xenstore.xswatch import xswatch
@@ -898,7 +899,7 @@ class XendDomain:
 
                 self._managed_domain_unregister(dominfo)
                 self._remove_domain(dominfo)
-                
+                XendDevices.destroy_device_state(dominfo)
             except Exception, ex:
                 raise XendError(str(ex))
         finally:
index c313efe2a899a057a7afa7ed338d5751390f4349..494a197b8e897bc5ae4b4c3fa22d6126bdafefad 100644 (file)
@@ -25,7 +25,7 @@ from xen.xend import sxp
 from xen.xend import XendRoot
 from xen.xend.XendLogging import log
 from xen.xend.XendError import XendError
-from xen.xend.XendConstants import DEV_MIGRATE_TEST
+from xen.xend.XendConstants import DEV_MIGRATE_TEST, VTPM_DELETE_SCRIPT
 from xen.xend.server.DevController import DevController
 
 import os
@@ -33,6 +33,10 @@ import re
 
 xroot = XendRoot.instance()
 
+def destroy_vtpmstate(name):
+    if os.path.exists(VTPM_DELETE_SCRIPT):
+        os.system(VTPM_DELETE_SCRIPT + " " + name)
+
 class TPMifController(DevController):
     """TPM interface controller. Handles all TPM devices for a domain.
     """
@@ -79,7 +83,7 @@ class TPMifController(DevController):
         if uuid:
             result['uuid'] = uuid
         if type:
-            result['type'] == type
+            result['type'] = type
 
         return result